package com.lfs.aspects;

import com.lfs.common.utils.StringUtils;
import com.lfs.util.JacksonUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.github.pagehelper.Page;
import com.google.common.base.Preconditions;

import java.io.Serializable;

public class Parameter implements Serializable {

    private static final long serialVersionUID = 4564527462967397985L;

    /**
     * 所有接口的参数接收实体
     */
    private String appId;

    private String param;

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    @JsonIgnore
    public <T> T getObject(Class<T> clazz) {
        Preconditions.checkArgument(StringUtils.isNotBlank(param));
        return JacksonUtils.readValue(param, clazz);
    }

    @JsonIgnore
    public <T> T getListObject(Class<T> clazz) {
        Preconditions.checkArgument(StringUtils.isNotBlank(param));
        return JacksonUtils.readListValue(param, clazz);
    }

    @JsonIgnore
    public <T> Page<T> getPageObject(Class<T> clazz) {
        Preconditions.checkArgument(StringUtils.isNotBlank(param));
        return JacksonUtils.readPageValue(param, clazz);
    }
}
